package com.efast.cafe.portal.service.common.impl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.efast.cafe.framework.constant.CommonConstant;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.cafe.portal.bean.common.LeaveMessageBean;
import com.efast.cafe.portal.dao.common.PortalCommonLaudDao;
import com.efast.cafe.portal.dao.common.PortalCommonLeavemsgDao;
import com.efast.cafe.portal.entity.common.PortalCommonLeavemsg;
import com.efast.cafe.portal.service.common.IPortalCommonLeavemsgService;
@Service
@Transactional
public class PortalCommonLeavemsgServiceImpl implements IPortalCommonLeavemsgService{
	
	private PortalCommonLeavemsgDao portalCommonLeavemsgDao;
	
	private PortalCommonLaudDao portalCommonLaudDao;
	
	@Autowired
	public void setPortalCommonLeavemsgDao(PortalCommonLeavemsgDao portalCommonLeavemsgDao) {
		this.portalCommonLeavemsgDao = portalCommonLeavemsgDao;
	}
	
	@Autowired
	public void setPortalCommonLaudDao(PortalCommonLaudDao portalCommonLaudDao) {
		this.portalCommonLaudDao = portalCommonLaudDao;
	}



	@Override
	public int addLeavemsg(PortalCommonLeavemsg msg) {
		msg.setCreateUser(SpringWebUtils.getRequestUser());
		msg.setCompanyCode(SpringWebUtils.getRequestCompany());
		portalCommonLeavemsgDao.addLeavemsg(msg);
		return msg.getId();
	}

	@Override
	public List<LeaveMessageBean> queryLeavemsg(Integer objectId, String objectType) {
		return portalCommonLeavemsgDao.queryLeavemsg(objectId, objectType, SpringWebUtils.getRequestCompany(), CommonConstant.BusObjectType.LEAVE_MESSAGE, SpringWebUtils.getRequestUser());
	}

	@Override
	public void delLeavemsg(Integer id, Integer objectId, String objectType) {
		// TODO Auto-generated method stub
		//刪除留言的點贊
		portalCommonLaudDao.deleteLeaveLaud(id, CommonConstant.BusObjectType.LEAVE_MESSAGE, SpringWebUtils.getRequestCompany());
		//刪除留言
		portalCommonLeavemsgDao.delLeavemsg(id, objectId, objectType, SpringWebUtils.getRequestCompany());
	}

	@Override
	public LeaveMessageBean queryLeavemsgById(Integer id,Integer objectId, String objectType) {
		return portalCommonLeavemsgDao.queryLeavemsgById(id,objectId, objectType, SpringWebUtils.getRequestCompany(), CommonConstant.BusObjectType.LEAVE_MESSAGE, SpringWebUtils.getRequestUser());
	}

}
